home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15136 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.5 KB  |  80 lines

  1. Path: ix.netcom.com!news
  2. From: jhewett@ix.netcom.com (Jerry Hewett)
  3. Newsgroups: comp.lang.c++
  4. Subject: Did I Miss Something?
  5. Date: Wed, 03 Apr 96 18:51:36 GMT
  6. Organization: Netcom
  7. Message-ID: <N.040396.105136.51@ix.netcom.com>
  8. NNTP-Posting-Host: tem-ca1-13.ix.netcom.com
  9. X-NETCOM-Date: Wed Apr 03 12:55:08 PM CST 1996
  10. X-Newsreader: Quarterdeck Message Center [2.00]
  11.  
  12. I recently discovered that if you want to throw code for Win95 you need a lot 
  13. more than six years of experience writing C code for Win3.x, so I've been 
  14. trying to (re)teach myself C++ over the past couple of days using the Coronado 
  15. Enterprises C++ TUTOR (more about this below).
  16.  
  17. My question revolves around the following code snippet taken from one of the 
  18. tutorial programs; specifically, what the heck is going on with "char *line_of_ 
  19. text"?  Where is the memory for the data being pointed to coming from?  My 
  20. theory is in the comment below.
  21.  
  22. Feel free to tell me how clueless I'm being.  ;-)
  23.  
  24. ----<snip>----
  25.  
  26. // OBJSTRNG.CPP, from Chapter 6 - More Encapsulation.  
  27.  
  28. class box {
  29.     int length;
  30.     int width;
  31.     char *line_of_text;
  32. public:
  33.     box(char *input_line);
  34.     void set(int new_length, int new_width);
  35.     int get_area(void);
  36. };
  37.  
  38. /*
  39.     Just guessing, but here goes...
  40.  
  41.     Below is the constructor for "box".  The object doesn't exist until the
  42.     constructor creates it.  Since a pointer to a "known" fixed-length string
  43.     is being passed to the constructor, the compiler determines the amount of
  44.     memory required to store the string "small box ", allocates space for it
  45.     in the object, and copies it into this space.
  46.  
  47.     Once the object passes out of scope this "magically" created chunk of
  48.     memory allocation disappears along with the object... (???)
  49. */
  50.  
  51. box::box(char *input_line)
  52. {
  53.     length = 8;
  54.     width = 8;
  55.     line_of_text = input_line;
  56. }
  57.  
  58. main()
  59. {
  60.     box small("small box ");
  61.  
  62. }
  63.  
  64. ----<snip>----
  65.  
  66. So far (the past three days) I've learned more from the Coronado Enterprises 
  67. C++ TUTOR than from all of the books I bought that were supposed to help me 
  68. migrate from C to C++ *and* the seminars/courses I've attended on OOP/OOD.  I 
  69. should also confess that it's been more than a couple of years since my first 
  70. exposure to OOP; I took the class, but didn't have any contracts that required 
  71. C++ and/or objects, so nearly all of it vanished into the haze...
  72.  
  73. This tutorial is definitely worth the $15 shareware fee as far as I can tell.  
  74. Now I just need to find a contract that will put it to use while it's all 
  75. occupying neural space near the forebrain! 8-)
  76.  
  77. Jerry H.
  78.  
  79.  
  80.